<?php
class RReviewLayoutsController extends AppController {

	var $name = 'RReviewLayouts';

	function index() {
		$this->RReviewLayout->recursive = 0;
		$this->set('rReviewLayouts', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid r review layout', true));
			$this->redirect(array('action' => 'index'));
		}
		
		// create layout review if necessary
		if( !$this->RReviewLayout->read( null, $id ) ){
			$this->set('customer', $this->RCustomer->read(null, $id));
			$this->redirect( array('action' => 'add', $id ));
		}
		else {
			$this->set('rReviewLayout', $this->RReviewLayout->read(null, $id));
		}
	}

	function add() {
		if (!empty($this->data)) {
			$this->RReviewLayout->create();
			if ($this->RReviewLayout->save($this->data)) {
				$this->Session->setFlash(__('The r review layout has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The r review layout could not be saved. Please, try again.', true));
			}
		}
		$rCustomerSites = $this->RReviewLayout->RCustomerSite->find('list');
		$rTemplates = $this->RReviewLayout->RTemplate->find('list');
		$this->set(compact('rCustomerSites', 'rTemplates'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid r review layout', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->RReviewLayout->save($this->data)) {
				$this->Session->setFlash(__('The r review layout has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The r review layout could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->RReviewLayout->read(null, $id);
		}
		$rCustomerSites = $this->RReviewLayout->RCustomerSite->find('list');
		$rTemplates = $this->RReviewLayout->RTemplate->find('list');
		$this->set(compact('rCustomerSites', 'rTemplates'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for r review layout', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->RReviewLayout->delete($id)) {
			$this->Session->setFlash(__('R review layout deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('R review layout was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>